package com.stormrage.edu.dao.edu.view.impl;

import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import com.stormrage.edu.dao.edu.view.EduChapterVideoDao;
import com.stormrage.entity.edu.view.EduChapterVideo;
import com.stormragetech.core.dao.MysBaseDao;
import com.stormragetech.core.exception.StormrageTechException;

/**
 * @Title: EduChapterVideoDaoImpl.java
 * @Package com.stormrage.edu.dao.edu.view.impl
 * @Description: 章节、课件关联 Dao
 * @author www.stormragetech.com
 * @date 2016年4月8日
 * @version V1.0
 */
@Repository
public class EduChapterVideoDaoImpl extends MysBaseDao implements EduChapterVideoDao {

	private static final Logger logger = LoggerFactory.getLogger(EduChapterVideoDaoImpl.class);

	@Override
	public Integer create(final EduChapterVideo arg0) throws StormrageTechException {

		logger.debug(" 【 Dao 】- 【 EduChapterVideoDao 】- 【 Create 】- 开始运行 ");

		final String query = "INSERT INTO edu_chap_video (chap_id, video_id) VALUES (:chapId, :videoId)";
		logger.debug(" 数据库执行语句为 " + query);

		Integer index = create(query, arg0);

		logger.debug(" 【 Dao 】- 【 EduChapterVideoDao 】- 【 Create 】- 完成运行 ");
		return index;
	}

	@Override
	public void deleteById(final Map<String, Object> map) throws StormrageTechException {

		logger.debug(" 【 Dao 】- 【 EduChapterVideoDao 】- 【 DeleteById 】- 开始运行 ");

		final String query = "DELETE FROM edu_chap_video WHERE id = :id";
		logger.debug(" 数据库执行语句为 " + query);

		update(query, map);
		logger.debug(" 【 Dao 】- 【 EduChapterVideoDao 】- 【 DeleteById 】- 完成运行 ");

	}

	@Override
	public void deleteByChapterId(final Map<String, Object> map) throws StormrageTechException {

		logger.debug(" 【 Dao 】- 【 EduChapterVideoDao 】- 【 DeleteByChapterId 】- 开始运行 ");

		final String query = "DELETE FROM edu_chap_video WHERE chap_id = :id";
		logger.debug(" 数据库执行语句为 " + query);

		update(query, map);
		logger.debug(" 【 Dao 】- 【 EduChapterVideoDao 】- 【 DeleteByChapterId 】- 完成运行 ");

	}

	@Override
	public void deleteByVideoId(final Map<String, Object> map) throws StormrageTechException {

		logger.debug(" 【 Dao 】- 【 EduChapterVideoDao 】- 【 DeleteByVideoId 】- 开始运行 ");

		final String query = "DELETE FROM edu_chap_video WHERE video_id = :id";
		logger.debug(" 数据库执行语句为 " + query);

		update(query, map);
		logger.debug(" 【 Dao 】- 【 EduChapterVideoDao 】- 【 DeleteByVideoId 】- 完成运行 ");

	}

	@Override
	public Integer queryCountById(final Map<String, Object> map) throws StormrageTechException {

		logger.debug(" 【 Dao 】- 【 EduChapterVideoDao 】- 【 QueryCountById 】- 开始运行 ");

		final String query = "SELECT COUNT(*) FROM edu_chap_video WHERE chap_id = :id";
		logger.debug(" 数据库执行语句为 " + query);

		Integer count = queryCount(query, map);

		logger.debug(" 【 Dao 】- 【 EduChapterVideoDao 】- 【 QueryCountById 】- 完成运行 ");
		return count;
	}

}
